package com.anlu.thread.ta1;

/**
 * @program: Thread-learning
 * @description:
 * @author: Mr.Wang
 * @create: 2019-01-30 14:50
 **/
public class Sequeuce {

    private MyLock lock = new MyLock();

    private int value;

    public int getNext(){
        lock.lock();

        value++;

        lock.unlock();
        return value;
    }

    public static void main(String[] args){
        Sequeuce s = new Sequeuce();

        new Thread(new Runnable() {
            @Override
            public void run() {
                while (true){
                    System.out.println(s.getNext());
                }
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                while (true){
                    System.out.println(s.getNext());
                }
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                while (true){
                    System.out.println(s.getNext());
                }
            }
        }).start();
    }
}
